/**
 * 将身份信息存入到cookie中
 * 借助js-cookie组件完成
 */
import Cookie from "js-cookie";

//声明工具类，导入操作cookie的工具方法
const CookieUsername = "CookieUsername";
const CookieToken = "CookieToken";
const CookieAvatart = "CookieAvatart";
export default {
    //将登录后的用户信息，保存到cookie中
    setUser:function(username,token,avatart) {
        Cookie.set(CookieUsername,username);
        Cookie.set(CookieToken,token);
        Cookie.set(CookieAvatart,avatart);
    },
    //从cookie中获取用户信息
    getUser:function (){
        return {
            name:Cookie.get(CookieUsername),
            token:Cookie.get(CookieToken),
            avatar:Cookie.get(CookieAvatart)
        }
    },
    clear:function() {
        Cookie.remove(CookieUsername);
        Cookie.remove(CookieToken);
        Cookie.remove(CookieAvatart);
    }
}
